<?php

class RateConfig_sb
{

    public $disk_type = array ( 'a' => "a" , 'b' => "b" , 'c' => "c" , 'd' => "d" );
    public $disk_idx = array ( 'a' => 1 , 'b' => 2 , 'c' => 3 , 'd' => 4 );
    public $splitArr = array ( "全部" , "成数" );
    public $diskArr = array ( "全部" , "a" , "b" , "c" , "d" );
    public $orderArr = array ( "" , "amount" , "number" );
    public $ratemodArr = array ( "目前赔率" , "平均赔率" , "输赢赔率" );
    public $playtypeArr = array ( );
    public $playtypeArr02 = array ( );
    public $playGroupArr = array ( );
    public $playGroupArr02 = array ( );
    public $subArr = array ( );
    public $showAllSubArr = array ( );
    public $showAllSubArr02 = array ( );
    public $showAllBetArr = array ( );
    public $showAllBetArr02 = array ( );
    public $bet4subArr = array ( );
    public $betXYArr = array ( );
    public $tbl;
    public $gametype = 1;
    public $rateFieldStr = "r01,r02,r03,r04,r05,r06,r07,r08,r09,r10,r11,r12,r13,r14,r15,r16,r17";
    public $rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17");
    public $rcBettypeToN = array ( );
    public $pounNum = 9;
    public $_5hFlag = true;
    public $maxSubId = 0;

    public function RateConfig_sb($gametype = 1)
    {
        global $g_gametype_3d;
        global $g_bet4subArr;
        global $g_betXYArr;
        if ( ! in_array($gametype , array ( 25,26)) )
        {
            exit("error gametype RC5H8H");
        }
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->gametype = $gametype;
        $this->bet4subArr = array();
        $this->betXYArr = array();
        $this->showAllBetArr02 = array ();
        $this->showAllBetArr = array ( );
        $this->showAllSubArr02 = array ();
        $this->showAllSubArr = array ();
       	$this->setPlaytypeArr8h();
		$this->subArr = array ( 1 => "一" , 2 => "二" , 3 => "三" );
		$this->maxSubId = 3;
		$this->rateFieldArr = array ( "r01" , "r02" , "r03" , "r04" , "r05" , "r06" , "r07" , "r08" , "r09" , "r10" , "r11" , "r12" , "r13" , "r14" , "r15" , "r16" , "r17");
        
    }
	public function setPlaytypeArr8h()
    {
        $this->playtypeArr = array (
            "r1" => "三军" ,
            "r2" => "短牌" ,
            "r3" => "豹子/全骰" ,
            "r4" => "长牌" ,
            "r5" => "总点数"
        );
        $this->playGroupArr = array (
            "r1" => array ( "0" , "1" ) ,//, "2" 
            "r2" => array ( "3" , "8"  ) ,
            "r3" => array ( "4","5" ) ,
            "r4" => array ( "6") ,
            "r5" => array ( "7")
        );
        $this->playtypeArr02 = $this->playtypeArr;
        $this->playGroupArr02 = $this->playGroupArr;
    }

    public function formateRateField($num)
    {
        return "r".str_pad(intval($num) , 2 , "0" , STR_PAD_LEFT);
    }

    public function chkG3G6Idx($bettype)
    {
        return false;
    }

    public function getNumCount($bettype)
    {
        return 1;
    }

    public function checkDiskType($disk_type)
    {
        return isset($this->disk_type[$disk_type]);
    }

    public function getBetTypeNumber($bettype)
    {
		switch($bettype )
		{
			case 3 :
			case 0 :
				return array ( "01" , "02" , "03" , "04" , "05" , "06");
				break;
			case 1 :
			case 2 :
			case 8 :
				return array ( "01" , "02" );
				break;
			case 4 :
				return array ( "01" , "02" , "03" , "04" , "05" , "06" );
				break;	
			case 5 :
				return array ( "01");
				break;
			case 6 :
				return array ( "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15");
				break;
			case 7 :
				return array ( "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" );
				break;
			default:
				return array ( );
				break;		
		}
    }

    public function checkBetNumber($bettype , $num)
    {
        $chkArr = $this->getBetTypeNumber($bettype);

        $arrIdx = array_search($num , $chkArr);
        if ( $arrIdx === false )
        {
            return false;
        }
        return $num === $chkArr[$arrIdx];
    }

    public function getRateFromRateArr($bettype , $num , $rateArr)
    {
        if ( is_array($num) )
        {
            $rateTemp = 9999;
            foreach ( $num as $val )
            {
                $val = intval($val);
                $rateIdx = "r".str_pad($val , 2 , "0" , STR_PAD_LEFT);
                if ( isset($rateArr[$rateIdx]) )
                {
                    $rateTemp = min($rateTemp , floatval($rateArr[$rateIdx]));
                }
                else
                {
                    return 0;
                }
            }
            return 9998 < $rateTemp?0:$rateTemp;
        }
        $num = intval($num);
        $rateIdx = "r".str_pad($num , 2 , "0" , STR_PAD_LEFT);
        if ( isset($rateArr[$rateIdx]) )
        {
            return floatval($rateArr[$rateIdx]);
        }
        return 0;
    }

    public function setRateArrDir($numArr , $addVal)
    {
        $reArr = array ( );
        foreach ( $numArr as $val )
        {
            $numIdx = "r".str_pad(intval($val) , 2 , "0" , STR_PAD_LEFT);
            $reArr[$numIdx] = $addVal;
        }
        return $reArr;
    }

    public function mystr_split($str , $len = 8 , $_5hNumberFlag = false)
    {
        $reArray = array ( );
        if ( 0 < strlen($str) )
        {
            $n = strlen($str) / $len;
            if ( 0 < strlen($str) % $len )
            {
                $n = $n + 1;
            }
            $i = 0;
            while ( $i < $n )
            {
                if ( $_5hNumberFlag )
                {
                    $reArray[] = str_pad(intval(substr($str , $len * $i , $len)) , 2 , "0" , STR_PAD_LEFT);
                }
                else
                {
                    $reArray[] = floatval(substr($str , $len * $i , $len));
                }
                ++ $i;
            }
        }
        return $reArray;
    }

    public function getBetContent($bettype , $num , $smFlag = false)
    {
        switch ( $bettype )
        {
           	case 0:
				return $num."点";
				break;
			case 1:
				return ($num==1?"大":"小");
				break;
			case 2:
				return ($num==1?"单":"双");
				break;
			case 3:
				$tmp=array("","11","22","33","44","55","66");
				return $tmp[intval($num)];
				break;
			case 4:
				$tmp=array("","111","222","333","444","555","666");
				return $tmp[intval($num)];
				break;
			case 5:
				return "全骰";
				break;
			case 6:
				$tmp=array("","12","13","14","15","16","23","24","25","26","34","35","36","45","46","56");
				return $tmp[intval($num)];
				break;
			case 7:
				$tmp=array("","4点","5点","6点","7点","8点","9点","10点","11点","12点","13点","14点","15点","16点","17点");
				return $tmp[intval($num)];
				break;
			case 8:
				return $num==1?"对子":"散牌";
				break;
            default :
                exit("error bettype");
                break;
        }
        return "";
    }

    public function getPaperOpen()
    {
        return date("Y-m-d");
    }

    public function my_array_fill_keys($keys , $value)
    {
        return array_combine($keys , array_fill(0 , count($keys) , $value));
    }

}

?>